<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="com.framework.entity.Global"%>
<%@ page import="com.biz.utils.ConfigUtil" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
    String resoursUrl = ConfigUtil.get("RESOURCES_URL");
%>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8">
<title>订单详情</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<script src="<%=resoursUrl%>resources/assets/js/jquery-2.1.qrcode.js"></script>
<script src="<%=resoursUrl%>resources/assets/js/jquery.qrcode-0.11.0.js"></script>
<jsp:include page="/jsp/inc_head.jsp"></jsp:include>
<style>
	table 
{ 
margin-left: auto; 
margin-right: auto; 
}

</style>
</head>
<body>
	<section class="am-g am-text-sm">
		<div class="am-u-sm-12 am-padding-0" id="orderTotal"></div>
		<div class="fenge"></div>
		<div class="am-u-sm-12 thtkSjtyXq" style="color:#acacac">
			<div class="am-u-sm-12">
				收货人 <span id="orderFullName"></span>
			</div>
			<div class="am-u-sm-12">
				联系电话 <span id="orderPhone"></span>
			</div>
			<div class="am-u-sm-12">
				收货地址 <span id="orderAddress"></span>
			</div>
			<div class="am-u-sm-12">
				付款时间 <span id="orderPayTime"></span>
			</div>
			<div class="am-u-sm-12">
				下单时间 <span id="orderCreateTime"></span>
			</div>
			<div class="am-u-sm-12 lianmengshanghu" style="display: none">
				联盟商户 <span id="companyName"></span>
			</div>
			<div class="am-u-sm-12 lianmengshanghu" style="display: none">
				商户地址 <span id="companyAddr"></span>
			</div>
			<div class="am-u-sm-12" id="divCode" style="display:none;">
	        	商品提货码
	        	<div class="am-u-sm-12 am-pad-none am-text-center">
	        		<div style="margin-top:28px;color:#000;" id="goodsOrderCode"></div>
	        		<div style="margin-top:28px;color:#000;margin: auto;" id="txm"></div>
	        		<div class="am-text-center" id="qrcode" style="margin-top:8px;vertical-align: middle; "></div>
	        	</div>
	        </div>
		</div>
	</section>

	<!--footer-->
	<div class="am-g gdDbdiv"></div>
	<a href="javascript:" class="footeNavbar botBtn" onclick="fanhui();">返回</a>

	<script>
		var ajaxpath = "${pageContext.request.contextPath}";
		var detailId = '${detailId}';
		var type = '${type}';
		$(function() {
			loadOrders();
		});
		function loadOrders() {
			var url = ajaxpath + '/order/loadMyOrderDetails.do?id=' + detailId
					+ '&type=' + type;
			$
					.get(
							url,
							function(result) {

								$("#orderTotal").html("");
								var htmlArray0 = [];
								var data = eval(result);
								$(data)
										.each(
												function(i) {
													var html = '';//商品信息
													var htmlBeg = '';//订单信息头
													var htmlEnd = '';//订单信息尾
													var orderState = '';//订单头状态分类
													var orderOperation = '';//订单尾操作
													var codeShow = 0;

													switch (data[i].state) {
													case 0:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colyellow">待付款</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">取消</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">付款</a>';
														break;
													case 1:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colblue">待发货</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">申请退款</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">联系卖家</a>';
																codeShow = 1;
														break;
													case 2:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colred">待收货</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">确认收货</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">申请退款</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">联系卖家</a>';
																codeShow = 1;
														break;
													case 3:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colgreen">已完成</div>';
														break;
													case 4:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colgreen">已完成</div>';
														break;
													case 5:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right coleee">退款审核中</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">撤销申请</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">退款详情</a>';
														break;
													case 6:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colyellow">退款成功</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">退款详情</a>';
														break;
													case 7:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colblue">待发货</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">申请退款</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">联系卖家</a>';
														break;
													case 8:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colyellow">退款成功</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">退款详情</a>';
														break;
													case 9:
														orderState = '<div class="am-u-sm-3 am-padding-0 am-text-right colred">退款失败</div>';
														orderOperation = '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;" style="margin-right: 8px;">退款详情</a>'
																+ '<a class="am-btn am-btn-default qbddCzBtn" href="javascript:;">联系客服</a>';
														break;
													default:
														break;
													}
													html = '<div class="am-u-sm-12 orderinfo">'
															+ '<div class="am-u-sm-3 am-padding-0">';
													if(data[i].mainType == '3')
													{
														html+= '<img src="<%=Global.OSSURL_MAINTYPE3%>/'+data[i].goodsPath+'" class="sptpimg" />';
													}else{
														html+= '<img src="<%=Global.OSSURL%>/'+data[i].goodsPath+'" class="sptpimg" />';
													}
													html+= '</div>'
															+ '<div class="am-u-sm-9 am-padding-0" >'
															+ '<div class="am-u-sm-12 am-padding-0 infoname">'
															+ data[i].goodsName
															+ '</div>'
															+ '<div class="am-u-sm-12 infogg">'
															+ data[i].typeValue1
															+ ifnullString(data[i].typeValue2)
															+ ifnullString(data[i].typeValue3)
															+ '</div>'
															+ '<div class="am-u-sm-12 am-padding-0" style="font-size:13px;">'
															+ '<div class="am-u-sm-6 am-padding-0">X'
															+ data[i].count
															+ '</div>';
															if(data[i].goodsType == '0')
															{
																html+=' <div class="am-u-sm-6 am-padding-0 am-text-right">'
																		+ toDecimal2(data[i].price)+'<span>券</span>';
															}else{
																html+=' <div class="am-u-sm-6 am-padding-0 am-text-right">';
																	+ toDecimal2(data[i].price)+'<span>元</span>';
															}
															html+='</div>'
															+ ' </div></div></div>';

													htmlBeg = '<div class="am-u-sm-12 am-padding-0">'
															+ '<div class="am-u-sm-12 qbddDdhZt">'
															+ '<div class="am-u-sm-9 qbddDdbh">订单编号 '
															+ data[i].code
															+ '</div>'
															+ orderState
															+
																
															'</div>'
															+ '<div class="am-u-sm-12 am-padding-0"  name="orderinfo'+data[i].code+'">';

													htmlEnd = ' </div>'
															+ '<div class="am-u-sm-12 ddxqSfyf">';
														if(data[i].goodsType == '0')
														{
															var coupssssssss = 0;
															if(data[i].couponsPayTotal == undefined)
															{
																coupssssssss = 0;
															}else{
																coupssssssss = data[i].couponsPayTotal;
															}
															if(toDecimal2(data[i].coinPayTotal)>0) {
																htmlEnd += '实付：<span class="colred">'+toDecimal2(coupssssssss)+'券</span><span class="fwfspan">(含服务费'+toDecimal2(data[i].detailPayTotal)+'元,久零币抵扣' + toDecimal2(data[i].coinPayTotal) + '元)';
															}else{
																htmlEnd += '实付：<span class="colred">'+toDecimal2(coupssssssss)+'券</span><span class="fwfspan">(含服务费'+toDecimal2(data[i].detailPayTotal)+'元)';
															}
														}else{
															if(toDecimal2(data[i].coinPayTotal)>0) {
																htmlEnd += '实付：<span class="colred">' + toDecimal2(data[i].detailPayTotal) + '元,久零币抵扣' + toDecimal2(data[i].coinPayTotal) + '元</span>';
															}else{
																htmlEnd += '实付：<span class="colred">' + toDecimal2(data[i].detailPayTotal) + '元</span>';
															}
															/*htmlEnd+=
																	+ '<span class="ddxqSfyfYf">(运费 ￥<span name="orderfreightTotal'+data[i].code+'">'
																	+ toDecimal2(data[i].detailfreightTotal)
																	+ '</span>)</span>';*/
														}

													htmlEnd+=  '</div></div>';
													var save = data[i].code;
													$("#goodsOrderCode").html(data[i].orderId);
													if (htmlArray0
															.indexOf(save) != -1) {
														$(
																"[name='orderinfo"
																		+ data[i].code
																		+ "']")
																.append(html);
														var payTotal = $(
																"[name='orderPaytotal"
																		+ data[i].code
																		+ "']")
																.html();
														payTotal = toDecimal2(accAdd(
																payTotal,
																data[i].detailPayTotal));
														$(
																"[name='orderPaytotal"
																		+ data[i].code
																		+ "']")
																.html(payTotal);
														var feiTotal = $(
																"[name='orderfreightTotal"
																		+ data[i].code
																		+ "']")
																.html();
														feiTotal = toDecimal2(accAdd(
																feiTotal,
																data[i].detailfreightTotal));
														$(
																"[name='orderfreightTotal"
																		+ data[i].code
																		+ "']")
																.html(feiTotal);

													} else {
														$("#orderTotal")
																.append(
																		htmlBeg
																				+ html
																				+ htmlEnd);
														//  if(orderState!=0){$("#orderList_"+htmlSwith).append(htmlBeg+html+htmlEnd);
														// }
														htmlArray0.push(save);
													}
													$("#orderPayTime").html(
															data[i].payTime);
													$("#orderCreateTime").html(
															data[i].createTime);
													$("#orderFullName").html(
															data[i].recName);
													$("#orderPhone").html(
															data[i].recPhone);
													$("#orderAddress").html(
															data[i].recAddr);
													if(data[i].goodsType == '1'){
														$(".lianmengshanghu").show();
														$("#companyName").html(
																data[i].companyName);
														$("#companyAddr").html(
																data[i].companyAddr);
													}
													if(codeShow == 1 && data[i].goodsType == '1'){
														//装载二维码和条形码
														createNewCode(data[i].orderId);
														createNewTxm(data[i].orderId);
														//展示
														$("#divCode").show();
													}		

												});
							});
		}
		function accAdd(arg1, arg2) { //浮点数运算加法
			var r1, r2, m;
			try {
				r1 = arg1.toString().split(".")[1].length;
			} catch (e) {
				r1 = 0;
			}
			try {
				r2 = arg2.toString().split(".")[1].length;
			} catch (e) {
				r2 = 0;
			}
			m = Math.pow(10, Math.max(r1, r2));
			return (arg1 * m + arg2 * m) / m;
		}

		function toDecimal2(x) {
			var f = parseFloat(x);
			if (isNaN(f)) {
				return 0.00;
			}
			var f = Math.round(x * 100) / 100;
			var s = f.toString();
			var rs = s.indexOf('.');
			if (rs < 0) {
				rs = s.length;
				s += '.';
			}
			while (s.length <= rs + 2) {
				s += '0';
			}
			return s;
		}
		
		
function ifnullString(stringpd) {
if(stringpd==null)
{
return '';
}
else
{
return ','+stringpd;
}
}
		function fanhui() {
			window.location.href = ajaxpath + "/jsp/order/orderList.jsp?guid="
					+ new Date();
		}
		
		
		function createNewCode(code)
		{
			$("#qrcode").html("");
			$("#qrcode").qrcode({
				"render": "image",///设置渲染方式:image\div\canvas,默认 canvas
				"mode":1,//设置为1\2 设置为文本提示效果
				"label":"扫码核券",//提示文本
				"fontcolor":"#323B44",//提示文本颜色
				"width": 200, //宽度 
    			"height":200, //高度
				"radius":"0.5",//圆润度
				"size":10,//尺寸
				"fill":"#000",//填充前景色
				"background":"#fff",//填充背景色
				"text": code,//链接地址
				"text-align": "center"
		 		//"url":"http://www.baidu.com"
			});
		}

		function createNewTxm(code)
		{

			var settings = {
				barWidth: 2,
				barHeight:50,
				showHRI:false
			};
			$("#txm").barcode(code, "code128",settings);
		}
	</script>
</body>


</html>



